pcase.el (\`): Try and handle large patterns better
authorStefan Monnier <monnier@iro.umontreal.ca>
Mon, 3 Jun 2024 17:26:10 +0000 (13:26 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Mon, 3 Jun 2024 17:40:39 +0000 (13:40 -0400)
commit16fc5b6c0c72464a75d9a84b754375662b3acec6
tree88bc6831578e836df2d68389d2b2f3c3cb64a674
parenteb9afd558ec506f1d349dbb61668d6231fda136f
pcase.el (\`): Try and handle large patterns better

Large backquote patterns tend to lead to very large and deeply
nested expansions, but they also tend to contain a lot of
"constant" subpatterns that can be compiled to quote patterns.
This patch does just that.  See discussion at
https://lists.gnu.org/archive/html/emacs-devel/2024-05/msg01140.html

* lisp/emacs-lisp/pcase.el (pcase--split-pred):
Improve the handling of pred-vs-quote so it also works with
quoted objects like cons cells, vectors, and strings.
Simplify the `pcase--mutually-exclusive-p` branch accordingly.
(pcase--expand-\`): New function, extracted from the \` pcase macro.
Make it recurse internally, and optimize backquote patterns to `quote`
patterns where possible.
(\`): Use it.

* test/lisp/emacs-lisp/pcase-tests.el (pcase-tests-vectors): Add tests
that were broken by a more naïve version of the optimization.
(pcase-tests-quote-optimization): New test.
lisp/emacs-lisp/pcase.el
test/lisp/emacs-lisp/pcase-tests.el